<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="发送验证码" id="sendCode">
    <script>
        var timer;
        var obj={
            s:20
        };
      
        var btn=document.getElementById("sendCode");
        function show(objs){//形参

            console.log(objs);
            if(objs.s<0){
                clearInterval(timer);
                this.disabled=false;//开启按钮
                this.value="发送验证码";
                objs.s=20;
            }else{
                this.disabled=true;//禁用按钮
                this.value=`${objs.s}秒后重发`;
                objs.s--;
            }
        }
        btn.onclick=function(){
            timer=setInterval(show.bind(btn,obj),500);
        };
    </script>
</body>
</html>